﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Xml.Linq;

namespace ZhangZhao.RenChangYou
{
    public partial class Default : System.Web.UI.Page
    {
        protected string Lat { get; set; }
        protected string Lng { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            string key = "9c4158f82a72555b121412650ff15b7e";

            string url = string.Format("http://api.map.baidu.com/geocoder/v2/?ak={0}&callback=renderOption&output=xml&address={1}&city={2}", key, "长寿路868号港中旅大厦", "上海市");

            HttpWebRequest httpWRequest = (HttpWebRequest)WebRequest.Create(url);
            using (HttpWebResponse httpWResponse = (HttpWebResponse)httpWRequest.GetResponse())
            {
                var result = XDocument.Load(httpWResponse.GetResponseStream());
                if (result != null)
                {
                    foreach (var ele in result.Elements())
                    {
                        this.Lat = ele.Element("result").Element("location").Element("lat").Value.ToString();
                        this.Lng = ele.Element("result").Element("location").Element("lng").Value.ToString();
                    }

                    result = null;
                }
            }

            httpWRequest = null;

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {

        }
    }
}